package indoor.nexd.com.nexdmap.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import indoor.nexd.com.nexdmap.R;
import indoor.nexd.com.nexdmap.model.MallModel;

/**
 * 显示商场名称的列表适配器.
 * Created by wangxu on 16/3/1.
 */
public class MallListAdapter extends BaseAdapter {


    private Context context;
    private List<MallModel> mallModelList;

    public MallListAdapter(Context context) {
        this.context = context;
        this.mallModelList = new ArrayList<>();
    }


    public void addMallList(List<MallModel> mallModelList) {
        this.mallModelList.addAll(mallModelList);
        this.notifyDataSetChanged();
    }


    @Override
    public int getCount() {
        return this.mallModelList.size();
    }

    @Override
    public MallModel getItem(int position) {
        return this.mallModelList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder viewHolder;

        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(android.R.layout.simple_list_item_1, null);
            viewHolder.textView = (TextView) convertView.findViewById(android.R.id.text1);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        MallModel mallModel = getItem(position);
        viewHolder.textView.setText(mallModel.getMallCName());
        return convertView;
    }

    private static class ViewHolder {
        TextView textView;
    }
}
